#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>

struct stepInfo
{
    int x;
    int y;
    int step;

    stepInfo(int x, int y, int step) : x(x), y(y), step(step) {};
};

int direction[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

int main()
{
    int m, n, i, j, k, l;

    scanf("%d,%d,%d,%d,%d,%d", &m, &n, &i, &j, &k, &l);

    std::vector<std::vector<int>> visited(m, std::vector<int>(n, 0));
    visited[i][j] = 1;
    visited[k][l] = 1;

    std::queue<stepInfo> bfs_que;
    bfs_que.push(stepInfo(i, j, 0));
    bfs_que.push(stepInfo(k, l, 0));

    int max_step = 0;

    while (!bfs_que.empty())
    {
        auto node_info = bfs_que.front();
        bfs_que.pop();

        for (int i = 0; i < 4; i++)
        {
            int x = node_info.x + direction[i][0];
            int y = node_info.y + direction[i][1];
            if (x >= 0 && x < m && y >= 0 && y < n && visited[x][y] == 0)
            {
                visited[x][y] = 1;
                bfs_que.push(stepInfo(x, y, node_info.step + 1));
                max_step = std::max(max_step, node_info.step + 1);
            }
        }
    }

    std::cout << max_step << std::endl;
    return 0;
}